/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Rev_Ulti.java
 *
 * Created on Feb 25, 2009, 4:54:53 PM
 */

/**
 *
 * @author Himanshu  Sharma
 */
import java.awt.event.MouseListener ;
import java.awt.event.MouseEvent ;
import java.awt.event.InputEvent ;

public class Rev_Ulti extends javax.swing.JFrame {
    double money_Won = 0.0, init_money =0.0;
    Game G;
    String stage = "1" ;

    /** Creates new form Rev_Ulti */
    public Rev_Ulti() {
        init_money = 5.0;
        initComponents();
        G = new Game();
        b3.setVisible(false);
        l3.setText(Double.toString(init_money));
        this.setVisible(true);
        addMouseListener( new Rev_Ulti.CheckMouse() ) ;
    }

        public Rev_Ulti( double init_money ) {
            this.init_money = init_money;
            initComponents();
            G = new Game();
            b3.setVisible(false);
            l3.setText(Double.toString(init_money));
            this.setVisible(true);
            addMouseListener( new Rev_Ulti.CheckMouse() ) ;
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        l1 = new javax.swing.JLabel();
        l2 = new javax.swing.JLabel();
        l4 = new javax.swing.JLabel();
        b1 = new javax.swing.JButton();
        l5 = new javax.swing.JLabel();
        l3 = new javax.swing.JLabel();
        b2 = new javax.swing.JButton();
        b3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        l1.setFont(new java.awt.Font("Tahoma", 0, 14));
        l1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        l1.setText("Ultimatum");

        l2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        l2.setText(" Player 1 has offered you ($)");

        l4.setText("What would you like to do ?");

        b1.setText("Accept");
        b1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b1ActionPerformed(evt);
            }
        });

        l5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        l3.setText("5");

        b2.setText("Reject");
        b2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b2ActionPerformed(evt);
            }
        });

        b3.setText("Next");
        b3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(314, 314, 314)
                        .addComponent(l1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(193, 193, 193)
                        .addComponent(l2)
                        .addGap(18, 18, 18)
                        .addComponent(l3, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(263, 263, 263)
                                .addComponent(b1)
                                .addGap(39, 39, 39)
                                .addComponent(b2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addContainerGap(271, Short.MAX_VALUE)
                                .addComponent(l4, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addComponent(l5, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(314, 314, 314)
                        .addComponent(b3)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(l1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(l2)
                    .addComponent(l3, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(l5, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(l4, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(b2)
                            .addComponent(b1))))
                .addGap(39, 39, 39)
                .addComponent(b3)
                .addContainerGap(52, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void b1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b1ActionPerformed
        money_Won = init_money;

        l4.setText("<html><p> You accepted the amount <p> You won $ " + money_Won + "</p></html>" );
        l2.setText("");
        b1.setVisible(false);
        b2.setVisible(false);
        b3.setVisible(true);
        l3.setText("");
}//GEN-LAST:event_b1ActionPerformed

    private void b2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b2ActionPerformed
        money_Won = 0.0;
        
        l4.setText("<html><p> You Rejected the amount <p> Both players lose $ " + money_Won + "</p></html>" );
        l2.setText("");
        b1.setVisible(false);
        b2.setVisible(false);
        b3.setVisible(true);
        l3.setText("");

}//GEN-LAST:event_b2ActionPerformed

    private void b3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b3ActionPerformed
        G.writeLog("Ultimatum_Player2_Version: $" + money_Won) ;
        this.setVisible(false);
        G.free = true;
    }//GEN-LAST:event_b3ActionPerformed

        @Override
    public synchronized void addMouseListener(MouseListener l) {
        super.addMouseListener(l);
    }

    class CheckMouse implements MouseListener{
        public void mousePressed(MouseEvent e) {}
        public void mouseReleased(MouseEvent e) {}
        public void mouseEntered(MouseEvent e) {}
        public void mouseExited(MouseEvent e) {}
        public void mouseClicked(MouseEvent e) {
            int modifiers = e.getModifiers();

            if ((modifiers & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) {
            if( stage.equals("2") ){
                G.writeLog("Ultimatum_Player2_Version: $" + money_Won) ;
                setVisible(false);
                G.free = true;
            }
            if( stage.equals("1") ){
            money_Won = init_money;
            l4.setText("<html><p> You accepted the amount <p> You won $ " + money_Won + "</p></html>" );
            l2.setText("");
            b1.setVisible(false);
            b2.setVisible(false);
            b3.setVisible(true);
            l3.setText("");
            stage = "2" ;
            }}
            if ((modifiers & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK) {}
            if ((modifiers & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) {
            if( stage.equals("1") ){
            money_Won = 0.0;
            l4.setText("<html><p> You Rejected the amount <p> Both players lose $ " + money_Won + "</p></html>" );
            l2.setText("");
            b1.setVisible(false);
            b2.setVisible(false);
            b3.setVisible(true);
            l3.setText("");
            stage = "2" ;
            }
        }

        }
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Rev_Ulti().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton b1;
    private javax.swing.JButton b2;
    private javax.swing.JButton b3;
    private javax.swing.JLabel l1;
    private javax.swing.JLabel l2;
    private javax.swing.JLabel l3;
    private javax.swing.JLabel l4;
    private javax.swing.JLabel l5;
    // End of variables declaration//GEN-END:variables

}
